from core.basehandler import BaseHandler
from core.room import Room
from core.action import Action
from core.support import get_game

#gun code
#from util.sessions import Session 


class EnterLivingQuarters(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)    # do basic initialization for every room
        self.enemy_alive = True
        
#gun code        
#         session = Session()
#         self.gun_onhand = False
#         self.gun_onhand = session['gun'] 
        
        
        # add inventory items
        
        # build list of actions
        self.add_action(Exit)
    
    # return description of room.
    def get_description(self):

        if self.enemy_alive == True:               
            game = get_game()
            if not 'gun' in game.player.inventory:
                
                desc = "You enter the living quarters unarmed. John Locke slaps you to death. See you in another life, brother."
            else:
                desc = '''You see a bald man standing in the living quarters. He is armed with a knife and a gun.'''


        else:
            desc = "With the intruder held hostage, you can now see Our Mutual Friend, a book of particular interest." 
        return desc
    
    # return image of room
    def get_image(self):
        if self.enemy_alive == True:
            return 'bitchslap.gif'
        else:
            return 'ourmutualfriend.jpg'

class LivingQuartersHandler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return EnterLivingQuarters

# define actions for this room

class Exit(Action):
    def __init__(self):
        Action.__init__(self, "Exit")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Exit"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'startingpoint'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
    def do_action(self,game,room,request):
        return 
    
    def is_enabled(self):
        game = get_game()
        if 'gun' in game.player.inventory:
            return True
        else:
            return False
